package com.suxin.thread;

/**
 * @author Tang
 * @classname Thread1
 * @description [  ]
 * @date 2021/2/25 9:32
 */

class Thread2 extends Thread {
    public int total;
    @Override
    public void run() {
        synchronized (this) {
            for (int i = 0; i < 50; i++) {
                total += i;
            }
            System.out.println(Thread.currentThread().getName() + "线程执行完成...");
            this.notify();
        }
    }
}

public class Thread1{
    public static void main(String[] args) {
        Thread2 thread2 = new Thread2();
        thread2.start();
        synchronized (thread2) {
            System.out.println(Thread.currentThread().getName() +"等待执行完毕...");
            try {
                thread2.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("计算结果为:" + thread2.total);
    }
}